package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.domain.Cls;
import cn.edu.wfit.modules.infomanagement.service.IClsService;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 班级维护Controller
 * 
 * @author 韩强
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/cls")
public class ClsController extends BaseController
{
    @Autowired
    private IClsService clsService;

    /**
     * 查询班级维护列表
     */
    @RequiresPermissions("system:cls:list")
    @GetMapping("/list")
    public TableDataInfo list(Cls cls)
    {
        startPage();
        List<Cls> list = clsService.selectClsList(cls);
        return getDataTable(list);
    }

    /**
     * 导出班级维护列表
     */
    @RequiresPermissions("system:cls:export")
    @Log(title = "班级维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cls cls)
    {
        List<Cls> list = clsService.selectClsList(cls);
        ExcelUtil<Cls> util = new ExcelUtil<Cls>(Cls.class);
        util.exportExcel(response, list, "班级维护数据");
    }

    /**
     * 获取班级维护详细信息
     */
    @RequiresPermissions("system:cls:query")
    @GetMapping(value = "/{clsId}")
    public AjaxResult getInfo(@PathVariable("clsId") Long clsId)
    {
        return success(clsService.selectClsByClsId(clsId));
    }

    /**
     * 新增班级维护
     */
    @RequiresPermissions("system:cls:add")
    @Log(title = "班级维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cls cls)
    {
        return toAjax(clsService.insertCls(cls));
    }

    /**
     * 修改班级维护
     */
    @RequiresPermissions("system:cls:edit")
    @Log(title = "班级维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cls cls)
    {
        return toAjax(clsService.updateCls(cls));
    }

    /**
     * 删除班级维护
     */
    @RequiresPermissions("system:cls:remove")
    @Log(title = "班级维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clsIds}")
    public AjaxResult remove(@PathVariable Long[] clsIds)
    {
        return toAjax(clsService.deleteClsByClsIds(clsIds));
    }
}
